//
//  UIBarButtonItem+Extension.swift
//  123
//
//  Created by pangjiaxing on 15/12/28.
//  Copyright © 2015年 pangjiaxing. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(imageName:String?=nil,title:String?=nil,targat:NSObject?,action:Selector) {
        
        self.init()
        
        let button=UIButton()

        button.addTarget(targat, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        if imageName != nil {
            
            button.setImage(UIImage(named: imageName!), forState: UIControlState.Normal)
            button.setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
            
           
        }
        
        if title != nil {
            button.setTitle(title, forState: UIControlState.Normal)
            button.setTitle(title, forState: UIControlState.Highlighted)
            // 设置字体的大小颜色
            button.titleLabel?.font = UIFont.systemFontOfSize(15)
            button.setTitleColor(UIColor(white: 80/255, alpha: 1), forState: UIControlState.Normal)
        }
        button.sizeToFit()
        customView=button
        
    }
}
